<template>
  <div class="app-container2">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">利率类型</label>
        <el-select v-model="query.aaa030" placeholder="请选择"   @keyup.enter.native="crud.toQuery" >
          <el-option v-for="item in dict.aaa030" :key="item.id" :value="item.value" :label="item.label" />
        </el-select>
        <el-date-picker
          v-model="query.aae003start"
          type="month"
          placeholder="选择月">
        </el-date-picker>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0"  :title="crud.status.title" width="60%">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-col :span="12">
          <el-form-item label="利率参数ID" prop="aaz153" v-show="false" >
            <el-input v-model="form.aaz153" style="width: 370px; " />
          </el-form-item>
          </el-col>
          <el-col :span="12">
          <el-form-item label="利率名称" prop="aaa032" v-show="false">
            <el-input v-model="form.aaa032" style="width: 370px;" />
          </el-form-item>
          </el-col>
          <el-col :span="12">
          <el-form-item label="利率类型" prop="aaa030">
            <el-select v-model="form.aaa030" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.aaa030"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
          </el-col>
          <el-col :span="12">
          <el-form-item label="利率" prop="aaa031">
            <el-input-number v-model="form.aaa031" size="medium"  :precision="4" :step="0.1" min="0" max="1"></el-input-number>

          </el-form-item>
          </el-col>

          <el-col :span="12">
          <el-form-item label="开始日期" prop="aae041">
            <el-date-picker
              v-model="form.aae041"
              type="month"
              format="yyyy-MM"
              placeholder="选择月">
            </el-date-picker>
          </el-form-item>
          </el-col>
          <el-col :span="12">
          <el-form-item label="终止日期">
            <el-date-picker
              v-model="form.aae042"
              type="month"
              format="yyyy-MM"
              placeholder="选择月">
            </el-date-picker>
          </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注">
              <el-input type="textarea" v-model="form.aae013"  />
            </el-form-item>
          </el-col>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" border   :header-cell-style="{background:'#f5f7fa', color:'#777'}" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
<!--        <el-table-column prop="aaz153" label="利率参数ID"  />-->
<!--        <el-table-column prop="aaa032" label="利率名称" width="180px"/>-->
        <el-table-column prop="aaa030" label="利率类型" width="220px" align="center" header-align="center">
          <template slot-scope="scope">
            {{ dict.label.aaa030[scope.row.aaa030] }}
          </template>
        </el-table-column>
        <el-table-column prop="aaa031" label="利率" width="180px" align="center" header-align="center"/>
        <el-table-column prop="aae041" label="开始日期" width="220px" :formatter="formatDate" align="center" header-align="center"/>
        <el-table-column prop="aae042" label="终止日期" width="220px" :formatter="formatDate" align="center" header-align="center"/>
        <el-table-column prop="aae013" label="备注" header-align="center"/>
        <el-table-column v-if="checkPer(['admin','accountAa03:edit','accountAa03:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudAccountAa03 from '@/views/ynsb_comm/aa03/js/accountAa03'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { aaz153: null, aaa032: null, aaa030: null, aaa031: null, aae013: null, aae011: null, aae036: null, aae041: null, aae042: null, aab359: null }
export default {
  name: 'AccountAa03',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['aaa030'],
  cruds() {
    return CRUD({ title: '利率', url: 'api/accountAa03', idField: 'aaz153', sort: 'aaz153,desc', crudMethod: { ...crudAccountAa03 }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'accountAa03:add'],
        edit: ['admin', 'accountAa03:edit'],
        del: ['admin', 'accountAa03:del']
      },
      rules: {
        aaa030: [
          { required: true, message: '利率类型不能为空', trigger: 'blur' }
        ],
        aaa031: [
          { required: true, message: '利率不能为空', trigger: 'blur' }
        ],
        aae041: [
          { required: true, message: '开始日期不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'aaa030', display_name: '利率类型' }
      ]
    }
  },
  methods: {

    // 日期格式转换
    formatDate(row, column, cellValue) {
      // 格式化日期为 YYYY-MM-DD
      if (cellValue !== null && cellValue !== undefined) {
        const year = cellValue.toString().substring(0, 4)
        const month = cellValue.toString().substring(4, 6)
        return `${year}-${month}`
      } else {
        return '--'
      }
    },
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style lang="scss" scoped>
.app-container2 {
  padding: 10px 14px;
  background: #f0f2f58c;

  .head-container {
    background-color: #fff;
    height: 98%;
    padding: 10px;
  }

   .el-table{
    height: calc(100vh - 260px);
    overflow: auto;
  }
}
</style>

